<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <table border="1">
      <tbody>
        <tr>
          <td>1</td>
          <td>2</td>
          <td>3</td>
          <td>4</td>
          <td>5</td>
        </tr>
        <tr>
          <td>10</td>
          <td>9</td>
          <td>8</td>
          <td>7</td>
          <td>6</td>
        </tr>
        <tr>
          <td>11</td>
          <td>12</td>
          <td>13</td>
          <td>14</td>
          <td>15</td>
        </tr>
        <tr>
          <td>20</td>
          <td>19</td>
          <td>18</td>
          <td>17</td>
          <td>16</td>
        </tr>
        <tr>
          <td>21</td>
          <td>22</td>
          <td>23</td>
          <td>24</td>
          <td>25</td>
        </tr>
      </tbody>
    </table>
    <script>
      let flag = true;
      const table = document.body.children[0];
      const rows = table.rows;
      for (let i = 0; i < rows.length; i++) {
        const cells = rows[i].cells;
        for (let j = 0; j < cells.length; j++) {
          if (flag) {
            cells[j].innerText = j + 1 + i * cells.length;
          } else {
            cells[4 - j].innerText = j + 1 + i * cells.length;
          }
        }
        flag = !flag;
      }
    </script>
  </body>
</html>
